package com.zb.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zb.entity.CustomerAuthorDefaultData;
import com.zb.mapper.CustomerAuthorDefaultDataMapper;
import com.zb.service.CustomerAuthorDefaultDataService;
import com.zb.service.RoleAuthorDefaultDataService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;

/**
 * @Author WEN
 * @Date 2024/5/8 0008
 **/
@Service
public class CustomerAuthorDefaultDataServiceImpl extends ServiceImpl<CustomerAuthorDefaultDataMapper, CustomerAuthorDefaultData> implements CustomerAuthorDefaultDataService {
    @Resource
    private CustomerAuthorDefaultDataMapper customerAuthorDefaultDataMapper;
    @Resource
    private RoleAuthorDefaultDataService roleAuthorDefaultDataService;


    // 保存商家权限
    @Override
    public void saveCustomerAuthor(Long custAccId) {
        // 获取总后台的权限数据
        List<CustomerAuthorDefaultData> allAdmAuthor = customerAuthorDefaultDataMapper.getAllAdmAuthor();
        if (CollectionUtil.isEmpty(allAdmAuthor)) {
            return;
        }
        allAdmAuthor.forEach(t -> {
            t.setId(IdWorker.getId());
            t.setCustAccId(custAccId);
            t.setDisabled(false);
        });
        this.saveBatch(allAdmAuthor);
        roleAuthorDefaultDataService.saveRoleAuthor(custAccId, allAdmAuthor);
    }
}
